package controllers

import (
	"github.com/fogleman/gg"
	"path/filepath"
	"github.com/astaxie/beego/logs"
)

type ResrouceController struct {
	BaseController
}

//显示当前背景图片
func (this *ResrouceController) Get(){
	file, err := gg.LoadImage("static/img/background.jpg")
	if err != nil {
		this.OutPutError(err)
	}
	this.OutputImg(file, "jpeg")
}

//更改背景图片
func (this *ResrouceController)  Put() {
	file, header, err := this.GetFile("bg")
	if err != nil {
		this.OutPutError(err)
	}
	if file != nil {
		extension := filepath.Ext(header.Filename)
		logs.Info(extension)
		fileName := header.Filename
		logs.Info(fileName)
		err := this.SaveToFile("bg", "static/img/background.jpg")
		if err != nil {
			this.OutPutError(err)
		}
		this.OutPut("", "更改图片成功")
	}
	this.OutPut("", "文件为空")

}